package com.yanqu.road.server.cmd.blacklist;

import com.yanqu.road.pb.player.BlacklistProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.BlacklistModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;


@Cmd(code = Protocol.S_BLACKLIST_CANCEL, desc = "取消黑名单")
public class CancelBlacklistCmd extends AbstractCommand {
	private long blacklistUserId;
	private long blacklistUserServerId;
	private int type;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		BlacklistProto.BlacklistCancelReqMsg reqMsg = BlacklistProto.BlacklistCancelReqMsg.parseFrom(packet.getBytes());
		blacklistUserId = reqMsg.getBlacklistUserId();
		blacklistUserServerId = reqMsg.getBlacklistUserServerId();
		type = reqMsg.getType();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ret = player.getModule(BlacklistModule.class).cancelBlacklist(type, blacklistUserId, blacklistUserServerId);
	}

	@Override
	public void sendData(GamePlayer player) {
		BlacklistProto.BlacklistCancelRespMsg.Builder respMsg = BlacklistProto.BlacklistCancelRespMsg.newBuilder();
		respMsg.setRet(ret);
		respMsg.setBlacklistUserId(blacklistUserId);
		respMsg.setBlacklistUserServerId(blacklistUserServerId);
		respMsg.setType(type);
		player.sendPacket(Protocol.U_BLACKLIST_CANCEL, respMsg);
	}
}
